package application;

import application.dao.DBService;
import application.dao.entity.EnrollUser;
import application.dao.entity.RollCount;
import application.dao.entity.User;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import java.beans.BeanInfo;
import java.beans.beancontext.BeanContext;
import java.util.List;

public class Manager_control_competition_controller extends BaseController {

    @FXML
    public TextField num_older;
    @FXML
    public TextField num_audlt;
    @FXML
    public TextField num_youg;
    @FXML
    public TextField num_woman;
    @FXML
    public TextField num_man;
    @FXML
    public TextField num_total;
    @FXML
    public ListView listUser;
    @FXML
    private Button biMu;

    @FXML
    private TextField inputInfo;

    @FXML
    private MenuItem menu_join_competitons;

    @FXML
    private Button startEnroll;

    @FXML
    private Menu menu_main;

    @FXML
    private Menu onCheckMenu_main;

    @FXML
    private Button kaiMu;

    @FXML
    private RadioButton isman;

    @FXML
    private Menu menu_join;

    @FXML
    private Button approvalNotOK;

    @FXML
    private RadioButton iswoman;

    @FXML
    private MenuItem menu_join_users;

    @FXML
    private Button approvalOK;

    @FXML
    private Menu menu_informations;

    @FXML
    private Button entireList;

    @FXML
    private Menu menu_scores;

    @FXML
    void onClickToKaiMu(ActionEvent event) {

    }

    @FXML
    void onClickToBiMu(ActionEvent event) {

    }

    @FXML
    void onClickToStartEnroll(ActionEvent event) {

    }

    @FXML
    void onClickIsMan(ActionEvent event) {

    }

    @FXML
    void onClickIsWoman(ActionEvent event) {

    }

    @FXML
    void onButtonApprovalOK(ActionEvent event) {
        auditEnrollUser(1);
    }

    @FXML
    void onButtonApprovalNotOK(ActionEvent event) {

        auditEnrollUser(0);
    }

    private void auditEnrollUser(int i) {
        Object auditEnrollUser = map.get("auditEnrollUser");
        if (null != auditEnrollUser) {
            EnrollUser user = (EnrollUser) auditEnrollUser;
            Boolean aBoolean = DBService.auditEnRolledUser(user.getUserName(), i);
            BaseUtil.info("result:" + aBoolean);
        } else {
            BaseUtil.info("无审核人员");
        }
    }


    @FXML
    void onClickToSearhForEntireList(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_main(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_person(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_join_users(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_join_competitons(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_scores(ActionEvent event) {

    }

    @FXML
    void onCheckMenu_informations(ActionEvent event) {

    }


    @Override
    public void init() {
        showList();
        showCount();
    }

    private void showCount() {
        RollCount rollCount = DBService.queryRollCount();
        if (null != rollCount) {
            num_total.setText(rollCount.getTotal() + "");
            num_man.setText(rollCount.getMan() + "");
            num_woman.setText(rollCount.getWoman() + "");
            num_youg.setText(rollCount.getAge1() + "");
            num_audlt.setText(rollCount.getAge2() + "");
            num_older.setText(rollCount.getAge3() + "");
        }
    }

    private void showList() {
        List<EnrollUser> enrollUsers = DBService.listEnrollUser();
        if (null != enrollUsers) {
            enrollUsers.forEach(item -> listUser.getItems().add(getUserLabel(item)));
        }
    }

    Label getUserLabel(EnrollUser user) {
        String text = BaseUtil.formatDate(user.getApplicationTime());
        String show = text += "  [%s] %s";
        Label label = new Label(String.format(show, user.getRealName(), user.getUserName()));
        label.setAlignment(Pos.CENTER);
        label.setTextFill(Color.valueOf("#cc8eff"));
        Font font = Font.font("Comic Sans MS Bold", 16);
        label.setFont(font);
        return label;
    }
}
